# coding=utf-8

from rs_label.util.rs_image import RSImage
from rs_label.util import basic_func
from rs_label.tools.db.db_conn import Connection
from numpy import *
from scipy.misc import imsave

import os


def main():

    conn = Connection("sqlite3")
    conn.open_conn(db_path="/usr/data/remote_sensing/crowdsourcing_label/db/rs_label.db")
    rs_image = RSImage("GF2_shanghai_ps", conn, "/usr/data/remote_sensing/crowdsourcing_label/rs_images/GF2_shanghai.mat")
    data = basic_func.list2ndarray(rs_image.data)[0]
    print(data.shape, [rs_image.numX, rs_image.numY, rs_image.nband])
    data = reshape(data, [rs_image.numY, rs_image.numX, rs_image.nband])
    print(data.shape)
    rgb_image = data[:, :, ix_([2, 1, 0])]
    rgb_image = reshape(rgb_image, [rs_image.numY, rs_image.numX, 3])
    print(rgb_image[0, 0, :])
    image_save_name = os.path.join("/usr/data/remote_sensing/crowdsourcing_label/tmp", "%s.jpg" % "test")
    imsave(image_save_name, rgb_image)



if __name__ == "__main__":
    main()